package com.diliuzun.delivery.service;

import com.diliuzun.delivery.entity.User;
import com.diliuzun.delivery.util.PwdUtil;
import com.diliuzun.delivery.util.UUIDUtil;
import com.diliuzun.delivery.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.ArrayList;

@Service
@Transactional
public class UserService {
    @Autowired
    private UserMapper userMapper;
    public int addUser(User user){
        // 设置主键
        user.setYhbh(UUIDUtil.getUUID());
        // 默认状态为普通用户
        user.setYhsf("3");
        // 密码加密（默认加密成6位密文）
        user.setPwd(PwdUtil.getEncryptedPwd(user.getPwd()));
        return userMapper.addUser(user);
    }

    public int updateUser(User user){
        return userMapper.updateUser(user);
    }
    public int deleteUserById(Serializable id){
        return userMapper.deleteUserById(id);
    }

    public User selectUserById(Serializable id){
        return userMapper.selectUserById(id);
    }

    public User selectUser(User user){
        // 密码加密
        user.setPwd(PwdUtil.getEncryptedPwd(user.getPwd()));
        return userMapper.selectUser(user);
    }

    public ArrayList<User> selectUsers(User user){
        return userMapper.selectUsers(user);
    }
}
